package ch0624.case03;

public class Bank implements Runnable{
    private int number=0;
    public void setMoney(int m){
        number=m;
    }
    public void run(){
        while (true){
            String name=Thread.currentThread().getName();
            if (name.equals("one")){
                if (number<=150){
                    System.out.println(name+"的状态");
                    return;
                }
                number+=10;
                System.out.println("我是"+name+",现在number="+number);
            }
            if (Thread.currentThread().getName().equals("two")){
                if (number<=0){
                    System.out.println(name+"进入死亡状态");
                    return;
                }
                number-=100;
                System.out.println("我是"+name+",现在number="+number);
            }
            try {
                Thread.sleep(800);
            }catch (InterruptedException e){
                e.getStackTrace();
            }
        }
    }
}
